package com.liang.paul.officelite.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.liang.paul.officelite.R;
import com.liang.paul.officelite.beams.OfficeUser;
import com.liang.paul.officelite.holders.MemberListHolder;

import java.util.ArrayList;

/**
 * Created by paulliang on 16/5/30.
 */
public class MemberAdpter extends BaseAdapter {

    Context context;
    ArrayList<OfficeUser> datas;

    public MemberAdpter(Context context, ArrayList<OfficeUser> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MemberListHolder holder;
        if(convertView != null){
            holder = (MemberListHolder) convertView.getTag();
        }else {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_member, null);
            holder = new MemberListHolder(
                    (TextView)convertView.findViewById(R.id.txt_memberlist_name),
                    (TextView)convertView.findViewById(R.id.txt_memberlist_tel),
                    (TextView)convertView.findViewById(R.id.txt_memberlist_email));
            convertView.setTag(holder);
        }
        holder.setName(datas.get(position).getUsername());
        holder.setEmail(datas.get(position).getEmail());
        holder.setTel(datas.get(position).getMobilePhoneNumber());
        return convertView;
    }
}
